
clear all	
cd "${data}"
use "data1.dta", clear 


*CHES TABLE  

gen daysafter_CHES = daysafter if CHES_leftright!=.
 
* bivariate model 1
eststo CHES_0: mixed IMD3007_ CHES_leftright if CHES_1year==1 || country_: || election_: || respondent:

*base model
eststo CHES_1: mixed IMD3007_ daysafter CHES_leftright if CHES_1year==1 || country_: || election_: || respondent:

eststo CHES_2: mixed c.IMD3007_ c.daysafter##c.CHES_leftright if CHES_1year==1 || country_: || election_: || respondent: CHES_leftright 
margins, dydx(CHES_leftright) at(daysafter=(0(30)300)) post
marginsplot, ytitle("AME of a one-unit change in party position", size(3)) recastci(rarea) level(95) recast(line) plot1opts(color() lpattern(shortdash)) title("") addplot(hist daysafter_CHES, percent color(gs12%50) yaxis(2) ytitle("percent", size(3) axis(2)) yscale(range(0(5)25) axis(2) alt)) legend(off) xscale(range(0(30)300)) xlabel(0(30)300)


cd "${figures}"
graph save "figureD1.gph", replace
graph export "figureD1.png", replace 

*Table 1 in manuscript:

cd "${tables}"

esttab CHES_0 CHES_1 CHES_2 using tableD1.tex, replace ///
b(3) se(3) nogap transform(ln*: exp(2*@) 2*exp(2*@))



